<?php
	$validation_rules = array(
		"path" => array(
			"required" => true,
            #'path' => true,
            'maxlength' => 255
		),
		"title_en" => array(
            'maxlength' => 255
		),
		"title" => array(
            'maxlength' => 255
		),

// bug 3978        
//		"average_rating" => array(
//            'number' => true,
//            'maxlength' => 9
//		),
        
		"number_of_episodes" => array(
            'positiveInt' => true,
            'maxlength' => 9
		),
		"starting_original_episode_no" => array(
            'positiveInt' => true,
            'maxlength' => 9
		),

// bug 3978        
//		"nominal_duration[]" => array(
//            'number' => true,
//            'maxlength' => 9
//		),

		"forum_id" => array(
            'number' => true,
            'maxlength' => 9
		),
		"blog_url" => array(
            'maxlength' => 255  
		),
		"minisite_url" => array(
            'maxlength' => 255
		),
		"first_episode_time_onair[]" => array(  
		),
		"last_episode_time_onair[]" => array(
		),

// bug 3978
		"first_onair_information[]" => array(
        'maxlength' => 255
		),

		"publish_datetime[]" => array(
			"required" => true
		),
		"expire_datetime[]" => array(
			'required' => true
		)
	);
    
    if ($act==='view') {
        FormHelper::setReadonly(true);
        $validation_rules = array();
    }
?>
<?php
$from = isset($data['from']) ? $data['from'] : '';
$programme = isset($data['programme']) ? $data['programme'] : array();
$programme_diff = isset($data['programme_diff']) ? $data['programme_diff'] : array();
$programme_premium = isset($data['programme_premium']) ? $data['programme_premium'] : array();
$programme_subscription = isset($data['programme_subscription']) ? $data['programme_subscription'] : array();
$programme_ppv = isset($data['programme_ppv']) ? $data['programme_ppv'] : array();
$cast_highlight = isset($data['highlight_cast']) ? $data['highlight_cast'] : array();
$crew_highlight = isset($data['highlight_crew']) ? $data['highlight_crew'] : array();
$company_code_option = isset($data['company_code_option']) ? $data['company_code_option'] : array();
$category_list = isset($data['category_list']) ? $data['category_list'] : array();
$category_detail = isset($data['category_detail']) ? $data['category_detail'] : array();
$tvb_category_list = isset($data['tvb_category_list']) ? $data['tvb_category_list'] : array();
$tag_list  = isset($data['tag_list']) ? $data['tag_list'] : array();
$tag_list[1] = isset($data['tag_list'][1]) ? $data['tag_list'][1] : array();
$tag_list[2] = isset($data['tag_list'][2]) ? $data['tag_list'][2] : array();
$allow_tag = isset($data['allow_tag']) ? $data['allow_tag'] : array();
$code_list = isset($data['code_list']) ? $data['code_list'] : array();
$cpl_list = isset($data['cpl_list']) ? $data['cpl_list'] : array();
$video_folder_list = isset($data['video_folder_list']) ? $data['video_folder_list'] : array();
$image_folder_list = isset($data['image_folder_list']) ? $data['image_folder_list'] : array();
$arr_cast = isset($data['arr_cast']) ? $data['arr_cast'] : array();
$arr_crew = isset($data['arr_crew']) ? $data['arr_crew'] : array();
$cast_list = isset($data['cast_list']) ? $data['cast_list'] : array();
foreach ($cast_list as $key1=>$value1) {
	foreach ($value1 as $key2=>$value2) {
		$cast_list[$key1][$key2]['last_name'] = htmlentities($value2['last_name'], ENT_QUOTES, 'UTF-8');
		$cast_list[$key1][$key2]['first_name'] = htmlentities($value2['first_name'], ENT_QUOTES, 'UTF-8');
	}
}

//$remote_cast_list = isset($data['remotecast_list']) ? $data['remotecast_list'] : array();
$crew_list = isset($data['crew_list']) ? $data['crew_list'] : array();
foreach ($crew_list as $key1=>$value1) {
	foreach ($value1 as $key2=>$value2) {
		$crew_list[$key1][$key2]['last_name'] = htmlentities($value2['last_name'], ENT_QUOTES, 'UTF-8');
		$crew_list[$key1][$key2]['first_name'] = htmlentities($value2['first_name'], ENT_QUOTES, 'UTF-8');
	}
}

//$remote_crew_list = isset($data['remotecrew_list']) ? $data['remotecrew_list'] : array();
$form_action = ($act === 'view') ? "programme_switch.html" : "programme_step2.html?act=".$act."&step=".$step;
$programme_cat  =  $data['rootcategory'];
$publish = isset($data['unpublish']) ? $data['unpublish'] : 0;

$num_language_zh = language::getLanguageId(AC::LANGUAGE_ZH);
$num_language_en = language::getLanguageId(AC::LANGUAGE_EN);
?> 
<div id="programme-step2" class="mod ui-widget-content ui-helper-clearfix ui-corner-all <?php echo $act; ?>">

    <div class="hd ui-widget-header ui-helper-clearfix ui-corner-all"><h2><?php echo $act_text; ?> Programme</h2></div>

    <div class="bd">
    <?php FormHelper::StartForm('ane', AC::PDES_BASE_URL.$form_action) ?>
        <?php FormHelper::HiddenField('is_folder_update', '0') ?>
        <?php FormHelper::ErrorMessages($errors) ?>
        <?php FormHelper::HiddenField('id', $programme->id) ?>
        <?php FormHelper::HiddenField('language_id', $programme->language_id) ?>
        <?php FormHelper::HiddenField('folders', $programme->folders) ?>
		<?php FormHelper::HiddenField('available_tag_types', $programme->available_tag_types) ?>
		<?php FormHelper::HiddenField('highlighted_cast_roles', $programme->highlighted_cast_roles) ?>
        <?php FormHelper::HiddenField('status', $programme->status) ?>
        <?php FormHelper::HiddenField('created_at', $programme->created_at) ?>
        <?php FormHelper::HiddenField('created_by', $programme->created_by) ?>
	    <?php FormHelper::HiddenField('modified_at', $programme->modified_at) ?>
		<?php FormHelper::HiddenField('modified_by', $programme->modified_by) ?>
        <?php FormHelper::HiddenField('from', $from) ?>
        <?php FormHelper::HiddenField('folder_video_id', '') ?>
        <?php FormHelper::HiddenField('folder_video_act', '') ?>

        <fieldset class="ui-widget-content">
        	<legend class="ui-widget-header">Programme Key</legend>
            <?php 
                FormHelper::ProtectedField($programme->id, 'Programme ID');
                FormHelper::Separator();
                #FormHelper::ProtectedField('No', 'Telco');

			    FormHelper::TextField('title', $programme->zh_programme_name, 
										  'Programme Title (Chinese)', 
										  $programme_diff['zh_programme_name'], 'ruler input_status', 2);					 
				FormHelper::TextField('title_en', $programme->en_programme_name, 
										  'Programme Title (English)', 
										  $programme_diff['en_programme_name'], 'ruler input_status', 2);
                if (isset($data['publishLog']->status)) {
                    FormHelper::HiddenField('path', $programme->path);
                    FormHelper::ProtectedField($programme->path, 'Programme Path', false);
                } else {
                    FormHelper::TextField('path', $programme->path, 'Programme Path', $programme_diff['path'], 
                                              'ruler input_status', 1);
                }
                FormHelper::RadioButton('video_type', array('O'=>'O-Version','I'=>'I-Version'),  $programme->video_type, 'Video Type');                    
				FormHelper::CheckBox(
					'premium_items', 
					array(
						array('label'=>'Subscription','value'=>'subscription','checked'=>$programme_premium['premium_items']['subscription']),
						array('label'=>'Pay-Per-View','value'=>'ppv','checked'=>$programme_premium['premium_items']['ppv'])
					), 
					'Premium Items',
					false,
					false,
					0
				); 
				FormHelper::RadioButton('auto_publish', array(1=>'Yes',0=>'No'), $programme->auto_publish, 'Auto-publish');
	#		    FormHelper::RadioButton('premium_flag', array(1=>'Yes',0=>'No'), $programme->premium_flag, 'Premium');
			?>
        </fieldset>

<?php 
if('view'==$act ) {    
	if ($programme->auto_publish) { ?>
		<fieldset class="ui-widget-content auto_publish">
			<legend class="ui-widget-header">Auto Publish</legend>
			<?php FormHelper::DateTimePicker('auto_publish_start_datetime', $programme->auto_publish_starttime, 'Online Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
			<?php FormHelper::DateTimePicker('auto_publish_end_datetime', $programme->auto_publish_endtime, 'Offline Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
        </fieldset> <?php
	}

    if($programme->premium_flag) { 
?>
        <?php if (empty($data['unpublish']) || ($data['unpublish'] == 1 && isset($data['special_operation_premium']) && $data['special_operation_premium'] == TRUE)) { ?>
        <fieldset class="ui-widget-content premium_key">
            <legend class="ui-widget-header">Premium key</legend>
            <?php FormHelper::TextField('premium_title', $programme_premium['premium_title'], 'Programme Title (Chinese)', false, '', 2);?>
    		<?php FormHelper::TextField('premium_title_en', $programme_premium['premium_title_en'], 'Programme Title (English)', false, '', 2);?>
            <?php /* FormHelper::CheckBox(
                        'premium_items', 
                        array(
                            array('label'=>'Subscription','value'=>'subscription','checked'=>$programme_premium['premium_items']['subscription']),
                            array('label'=>'Pay-Per-View','value'=>'ppv','checked'=>$programme_premium['premium_items']['ppv'])
                        ), 
                        'Premium Items',
                        false,
                        false,
                        1
                      ); 

			 */
            ?>
            <?php # FormHelper::RadioButton('premium_auto_publish', array(1=>'Yes',0=>'No'), $programme_premium['premium_auto_publish'], 'Auto-publish (Premium)', false, 0); ?>
        </fieldset>
			<?php } ?> <?php 
	}

    if(false && $programme->premium_flag && $programme_premium['premium_items']['subscription']){ ?>
        <fieldset class="ui-widget-content premium_subscription">
            <legend class="ui-widget-header">Premium: Subscription</legend>
        	    <?php FormHelper::DateTimePicker('subscription_publish_datetime',  CommonUtils::formatDate($data['programme_subscription']['publish_datetime']), 'Online Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
    		    <?php FormHelper::DateTimePicker('subscription_expire_datetime', CommonUtils::formatDate($data['programme_subscription']['expire_datetime']), 'Offline Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
                <?php //FormHelper::RadioButton('subscription_free', array(1=>'Yes',0=>'No'), $programme_subscription['free'], 'Free', false, 0); ?>
                <?php FormHelper::Separator();?>
                
                <!--
                <div class="form-item" style="padding-bottom:0px">
                    <span class="grid-l">
                        <label>Country Allow / Deny :</label>
                    </span>
                    <span class="grid-r">
                    <?php
                    /*
                    $radioAllow =   $radioDeny  =   $select =   NULL;
                    if('allow' == $programme_subscription['subscription_country_allow_deny'])
                    {
                        $radioAllow = 'checked="checked" ';
                    }
                    else
                    {
                        $radioDeny = 'checked="checked" ';
                    }
                    if (empty($select))     $select =   array();
                    else    $select     =   explode(',', $select);
                    
                    $disabled = ('view' === $act)?' disabled="disabled"':'';
                     */
                    ?>
                    <label><input type="radio" name="subscription_country_allow_deny" value="allow" 
                        <?php //echo $radioAllow . $disabled; ?>/>Allow </label>
                    <label><input type="radio" name="subscription_country_allow_deny" value="deny" 
                        <?php //echo $radioDeny . $disabled; ?>/>Deny </label>
                    </span>
                </div>
                -->
                <?php
                    /*
                    $sub_country = isset($programme_subscription['subscription_country']) ? json_decode($programme_subscription['subscription_country']) : array();
                    FormHelper::CountryList('subscription_country','',
                    (array)$sub_country,
                    array(
                        'stat'=>AC::$country_stat,
                        'service'=>AC::$country_service,
                        'mandatory'=>1
                    )
                )
                     */
                ?>
                
		</fieldset> <?php 
	}

    if(false && $programme->premium_flag && $programme_premium['premium_items']['ppv']){ ?>
        <fieldset class="ui-widget-content premium_ppv">
            <legend class="ui-widget-header">Premium: Pay-Per-View</legend>
            <?php FormHelper::DateTimePicker('ppv_publish_datetime',  CommonUtils::formatDate($programme_ppv['publish_datetime']), 'Online Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
        	<?php FormHelper::DateTimePicker('ppv_expire_datetime',   CommonUtils::formatDate($programme_ppv['expire_datetime']), 'Offline Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
            <!--
            <div class="form-item" style="padding-bottom:0px">
                <span class="grid-l">
                    <label>Country Allow / Deny :</label>
                </span>
                <span class="grid-r">
                    <?php
                    /*       
                    $radioAllow =   $radioDeny  =   $select =   NULL;
                    if('allow' == $programme_ppv['ppv_country_allow_deny'])
                    {
                        $radioAllow = 'checked="checked" ';
                    }
                    else
                    {
                        $radioDeny = 'checked="checked" ';
                    }
                    if (empty($select))     $select =   array();
                    else    $select     =   explode(',', $select);
                    
                    $disabled = ('view' === $act)?' disabled="disabled"':'';
                     */
                    ?>
                    <label><input type="radio" name="ppv_country_allow_deny" value="allow" 
                        <?php //echo $radioAllow . $disabled; ?>/>Allow </label>
                    <label><input type="radio" name="ppv_country_allow_deny" value="deny" 
                        <?php //echo $radioDeny . $disabled; ?>/>Deny </label>
                </span>
            </div>
            -->
            <?php
                    /*
            $ppv_country = isset($programme_ppv['ppv_country']) ? json_decode($programme_ppv['ppv_country']) : array();
            FormHelper::CountryList('ppv_country','',
                (array)$ppv_country,
                array(
                    'stat'=>AC::$country_stat,
                    'service'=>AC::$country_service,
                    'mandatory'=>1
                )
            )
                     */
            ?>
		</fieldset> <?php 
	}
} else{ ?>
		<fieldset class="ui-widget-content auto_publish">
			<legend class="ui-widget-header">Auto Publish</legend>
			<?php FormHelper::DateTimePicker('auto_publish_start_datetime', $programme->auto_publish_starttime, 'Online Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
			<?php FormHelper::DateTimePicker('auto_publish_end_datetime', $programme->auto_publish_endtime, 'Offline Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
        </fieldset>

        <fieldset class="ui-widget-content premium_key">
            <legend class="ui-widget-header">Premium Key</legend>
            <?php FormHelper::TextField('premium_title', $programme_premium['premium_title'], 'Programme Title (Chinese)', false, '', 2);?>
    		<?php FormHelper::TextField('premium_title_en', $programme_premium['premium_title_en'], 'Programme Title (English)', false, '', 2);?>
            <?php /*FormHelper::CheckBox(
                        'premium_items', 
                        array(
                            array('label'=>'Subscription','value'=>'subscription','checked'=>$programme_premium['premium_items']['subscription']),
                            array('label'=>'Pay-Per-View','value'=>'ppv','checked'=>$programme_premium['premium_items']['ppv'])
                        ), 
                        'Premium Items',
                        false,
                        false,
                        1
					); */ 

            ?>
            <?php #FormHelper::RadioButton('premium_auto_publish', array(1=>'Yes',0=>'No'), $programme_premium['premium_auto_publish'], 'Auto-publish (Premium)', false); ?>

        </fieldset>
      
               <!-- 
        <fieldset class="ui-widget-content premium_subscription">
            <legend class="ui-widget-header">Premium: Subscription</legend>
        	    <?php FormHelper::DateTimePicker('subscription_publish_datetime',  CommonUtils::formatDate($data['programme_subscription']['publish_datetime']), 'Online Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
    		    <?php FormHelper::DateTimePicker('subscription_expire_datetime', CommonUtils::formatDate($data['programme_subscription']['expire_datetime']), 'Offline Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
                <?php //FormHelper::RadioButton('subscription_free', array(1=>'Yes',0=>'No'), $programme_subscription['free'], 'Free', false, 0); ?>
                <?php FormHelper::Separator();?>
                <div class="form-item" style="padding-bottom:0px">
                    <span class="grid-l">
                        <label>Country Allow / Deny :</label>
                    </span>
                    <span class="grid-r">
                    <?php
                    /*
                    $radioAllow =   $radioDeny  =   $select =   NULL;
                    if('allow' == $programme_subscription['subscription_country_allow_deny'])
                    {
                        $radioAllow = 'checked="checked" ';
                    }
                    else
                    {
                        $radioDeny = 'checked="checked" ';
                    }
                    if (empty($select))     $select =   array();
                    else    $select     =   explode(',', $select);
                    
                    $disabled = ('view' === $act)?' disabled="disabled"':'';
                     */
                    ?>
                    <label><input type="radio" name="subscription_country_allow_deny" value="allow" 
                        <?php //echo $radioAllow . $disabled; ?>/>Allow </label>
                    <label><input type="radio" name="subscription_country_allow_deny" value="deny" 
                        <?php //echo $radioDeny . $disabled; ?>/>Deny </label>
                    </span>
                </div>
          
                <?php
                    /*
                    $sub_country = isset($programme_subscription['subscription_country']) ? json_decode($programme_subscription['subscription_country']) : array();
                    FormHelper::CountryList('subscription_country','',
                    (array)$sub_country,
                    array(
                        'stat'=>AC::$country_stat,
                        'service'=>AC::$country_service,
                        'mandatory'=>1
                    )
                )
                     */
                ?>
                
        </fieldset>

        <fieldset class="ui-widget-content premium_ppv">
            <legend class="ui-widget-header">Premium: Pay-Per-View</legend>
        	<?php FormHelper::DateTimePicker('ppv_publish_datetime',  CommonUtils::formatDate($programme_ppv['publish_datetime']), 'Online Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
        	<?php FormHelper::DateTimePicker('ppv_expire_datetime',   CommonUtils::formatDate($programme_ppv['expire_datetime']), 'Offline Date Time (YYYY-MM-DD / HH:MM)', false, 1) ?>
           
            <div class="form-item" style="padding-bottom:0px">
                <span class="grid-l">
                    <label>Country Allow / Deny :</label>
                </span>
                <span class="grid-r">
                    <?php
                    /*
                    $radioAllow =   $radioDeny  =   $select =   NULL;
                    if('allow' == $programme_ppv['ppv_country_allow_deny'])
                    {
                        $radioAllow = 'checked="checked" ';
                    }
                    else
                    {
                        $radioDeny = 'checked="checked" ';
                    }
                    if (empty($select))     $select =   array();
                    else    $select     =   explode(',', $select);
                    
                    $disabled = ('view' === $act)?' disabled="disabled"':'';
                     */
                    ?>
                    <label><input type="radio" name="ppv_country_allow_deny" value="allow" 
                        <?php //echo $radioAllow . $disabled; ?>/>Allow </label>
                    <label><input type="radio" name="ppv_country_allow_deny" value="deny" 
                        <?php //echo $radioDeny . $disabled; ?>/>Deny </label>
                </span>
            </div>
            
            <?php
            /*
            $ppv_country = isset($programme_ppv['ppv_country']) ? json_decode($programme_ppv['ppv_country']) : array();
            FormHelper::CountryList('ppv_country','',
                (array)$ppv_country,
                array(
                    'stat'=>AC::$country_stat,
                    'service'=>AC::$country_service,
                    'mandatory'=>1
                )
            )
             */
            ?>
		</fieldset> --> <?php 
} ?>
        <fieldset class="ui-widget-content">
        	<legend class="ui-widget-header">Programme Category</legend>
			<!--
            <div id="programe-category-selector">
            	<?php FormHelper::DropDownList('parent_cpl_category', $programme_cat, $category_detail->parent_id, 'Programme Category'); ?>
            	<?php FormHelper::DropDownList('cpl_category_id', $category_list, $category_detail->id, 'Programme SubCategory', $programme_diff['cpl_category_id']); ?>
            </div>
			-->
                
            <?php FormHelper::EditableList($tvb_category_list, array('name'=>'tvb_category','restrict'=>1), 
                'TVB.COM Category', 'tvbcom_cat_id', 'tvb.com_cat', AC::AJAX_API_URL, false, 1) ?> 
        </fieldset>
    <!-- 
        <fieldset class="ui-widget-content">
            <legend class="ui-widget-header">Nature and Programme Types</legend>
				<?php #FormHelper::EditableList($tag_list[2], $allow_tag[2], 'Nature', '', 'programme_nature', AC::AJAX_API_URL) ?> 
        </fieldset>
-->
            <fieldset class="ui-widget-content">
                <legend class="ui-widget-header">Equivalent Programme</legend>
            <div class="form-item form-item-1c">
                    <span class="grid-l"><label>Equivalent Programme</label> :</span>
                    <span class="grid-r cpl">
                    <ul class="ui-widget-content">
<?php
foreach ($cpl_list as $cpl)
{
?>
<li><?php echo strtoupper($cpl->cpl_company_code);?><input type="hidden" value="<?php echo strtoupper($cpl->cpl_company_code);?>" name="cpl_company_code[]"/>&nbsp;<?php echo htmlentities($cpl->cpl_id, ENT_QUOTES, 'UTF-8');?>
<input type="hidden" value="<?php echo urlencode($cpl->cpl_id); ?>" name="cpl_id[]"/>&nbsp;<?php echo substr($cpl->effective_date,0,10);?>
<input type="hidden" value="<?php echo substr($cpl->effective_date,0,10);?>" name="effective_date[]"/>&nbsp;<?php if ($act!=='view') {?><a class="btn-del" href="">del</a><?php }?></li>
<?php
}
?>
                        </ul>
                        <table class="op">
						<tr><td>Company Name : </td><td><select class="field"><?php echo $company_code_option;?></select></td></tr>
                            <tr><td>Programme No. :</td><td><input class="field" type="text" value="" /></td></tr>
							<tr><td>Effective Date :   </td><td><input type="text" value="<?php echo date("Y-m-d");?>" class="datepicker field" /></td></tr>
                            <tr><td></td><td><input type="button" value="Add" class="btn ui-state-default ui-corner-all addcpl" /></td></tr>
                        </table>
                    </span>
                </div>
            </fieldset>

    	<fieldset class="ui-widget-content">
    		<legend class="ui-widget-header">Programme Basic Information</legend>
    		<?php 

                if(!array_key_exists($num_language_zh,$programme->programme_language))
                {
                    $obj = (object)array('programme_id'=>$programme->programme_id,'language_id'=>$num_language_zh,
                        'title'=>'','first_onair_information'=>'','settop_box_name'=>'',
                        'description'=>'','description_short'=>'','fact_background'=>'','objective'=>'');
                    $programme->programme_language[$num_language_zh] = $obj ;
                }
                 if(!array_key_exists($num_language_en,$programme->programme_language))
                {
                    $obj = (object)array('programme_id'=>$programme->programme_id,'language_id'=>$num_language_en,
                        'title'=>'','first_onair_information'=>'','settop_box_name'=>'',
                        'description'=>'','description_short'=>'','fact_background'=>'','objective'=>'');
                    $programme->programme_language[$num_language_en] = $obj ;
                }   
                $desc_zh = $programme->programme_language[$num_language_zh]->description;
                $desc_en = $programme->programme_language[$num_language_en]->description;
                
                $exad_zh = $programme->programme_language[$num_language_zh]->description_short;
                $exad_en = $programme->programme_language[$num_language_en]->description_short;
              
                $fact = $programme->fact_background;
                $objective = $programme->objective;
			    FormHelper::TextArea('description['.$num_language_zh.']',$desc_zh,
									 'Programme Writeup(Chinese)', $programme_diff['description']);
                FormHelper::TextArea('description['.$num_language_en.']', $desc_en, 		 
                                     'Programme Writeup(English)', $programme_diff['description']);

                FormHelper::TextArea('description_short['.$num_language_zh.']', $exad_zh, 		 
                                     'Programme Writeup(EXAD Chinese)', $programme_diff['description_short']);
                FormHelper::TextArea('description_short['.$num_language_en.']', $exad_en, 		 
                                     'Programme Writeup(EXAD English)', $programme_diff['description_short']);
               
                // bug 3978
                //FormHelper::TextArea('fact_background', $fact, 'Fact Background', $programme_diff['fact_background']);
                //FormHelper::TextArea('objective',$objective, 'Programme Objective', $programme_diff['objective']);
?>
            <?php FormHelper::TextField('number_of_episodes', $programme->number_of_episodes, 'No. of Episodes', $programme_diff['number_of_episodes'], 'number') ?>
            <?php FormHelper::TextField('starting_original_episode_no', $programme->starting_original_episode_no, 'Starting Episode No.', $programme_diff['starting_original_episode_no'], 'number') ?>
<?php
            // bug 3978
            /*
            <div class="form-item">
                <span class="grid-l"><label>Nominal Duration</label> :</span>
                <span class="grid-r">
				<input type="text" class="short" name="nominal_duration[]" value="<?php echo $programme->nominal_duration[0];?>" />hour(s) 
					<input type="text" class="short" name="nominal_duration[]" value="<?php echo $programme->nominal_duration[1];?>" />minute(s) 
					<input type="text" class="short" name="nominal_duration[]" value="<?php echo $programme->nominal_duration[2];?>" />second(s)
                </span>
            </div>
            */
?>
			<?php FormHelper::CheckBox('first_network_codes', $code_list, 'First Air Network', $programme_diff['first_network_codes']) ?>
			<?php 
				if ($act == 'view') {
					if ($programme_premium['premium_items']['subscription']) {
						FormHelper::DateTimePicker('subscription_publish_datetime',  CommonUtils::formatDate($data['programme_subscription']['publish_datetime']), 'Online Date Time (Subscription) (YYYY-MM-DD / HH:MM)', false, 1);
						FormHelper::DateTimePicker('subscription_expire_datetime', CommonUtils::formatDate($data['programme_subscription']['expire_datetime']), 'Offline Date Time (Subscription) (YYYY-MM-DD / HH:MM)', false, 1);
					}
					if ($programme_premium['premium_items']['ppv']) {
						FormHelper::DateTimePicker('ppv_publish_datetime',  CommonUtils::formatDate($programme_ppv['publish_datetime']), 'Online Date Time (PPV) (YYYY-MM-DD / HH:MM)', false, 1);
						FormHelper::DateTimePicker('ppv_expire_datetime',   CommonUtils::formatDate($programme_ppv['expire_datetime']), 'Offline Date Time (PPV) (YYYY-MM-DD / HH:MM)', false, 1);
					}
				} else {
					FormHelper::DateTimePicker('subscription_publish_datetime',  CommonUtils::formatDate($data['programme_subscription']['publish_datetime']), 'Online Date Time (Subscription) (YYYY-MM-DD / HH:MM)', false, 1);
					FormHelper::DateTimePicker('subscription_expire_datetime', CommonUtils::formatDate($data['programme_subscription']['expire_datetime']), 'Offline Date Time (Subscription) (YYYY-MM-DD / HH:MM)', false, 1);
					FormHelper::DateTimePicker('ppv_publish_datetime',  CommonUtils::formatDate($programme_ppv['publish_datetime']), 'Online Date Time (PPV) (YYYY-MM-DD / HH:MM)', false, 1);
					FormHelper::DateTimePicker('ppv_expire_datetime',   CommonUtils::formatDate($programme_ppv['expire_datetime']), 'Offline Date Time (PPV) (YYYY-MM-DD / HH:MM)', false, 1);
				}
			?>
    		<?php FormHelper::DateTimePicker('first_episode_time_onair', $programme->first_episode_time_onair, 'First Episode On Air Date Time (YYYY-MM-DD / HH:MM)', $programme_diff['first_episode_time_onair']) ?>
    		<?php FormHelper::DateTimePicker('last_episode_time_onair', $programme->last_episode_time_onair, 'Last Episode On Air Date Time (YYYY-MM-DD / HH:MM)', $programme_diff['last_episode_time_onair']) ?>
            
            <?php 
// bug 3978
				FormHelper::TextField('first_onair_information['.$num_language_zh.']', $programme->programme_language[$num_language_zh]->first_onair_information, 'First On Air Information<br />(Chinese)', $programme_diff['first_onair_information']);
				FormHelper::TextField('first_onair_information['.$num_language_en.']', $programme->programme_language[$num_language_en]->first_onair_information, 'First On Air Information<br />(English)', $programme_diff['first_onair_information']);
			?>
    		<?php 
			//bug 3978
			//FormHelper::DateTimePicker('first_time_onair', $programme->first_time_onair, 'First Air Date/Time (YYYY-MM-DD / HH:MM)', $programme_diff['first_time_onair']) 
			?>

<?php 
if(in_array($data['_gn'],array('admin','proofreader','editor'))){
	FormHelper::DateTimePicker('publish_datetime', $programme->publish_datetime, 'Publish Date/Time (YYYY-MM-DD / HH:MM)', $programme_diff['publish_datetime'],1);
	FormHelper::DateTimePicker('expire_datetime', $programme->expire_datetime, 'Expiry Date/Time (YYYY-MM-DD / HH:MM)', $programme_diff['expire_datetime'],1);
} 
?>
            <?php 
// bug 3978
//FormHelper::Duration('Production Period <br /> (YYYY-MM-DD)', 'production_start_date', 'production_end_date', $programme->production_start_date, $programme->production_end_date, $programme_diff['production_start_date'] && $programme_diff['production_end_date']) ?>
            <?php 
// bug 3978
//FormHelper::TextField('average_rating', $programme->average_rating, 'Average Rating', $programme_diff['average_rating'], 'number') ?>
    		<?php 
                //$m_key = htmlentities($programme->meta_keywords, ENT_QUOTES, 'UTF-8');
                $meta_key_encode = $programme->meta_keywords;
			    
                //$m_desc = htmlentities($programme->meta_description, ENT_QUOTES, 'UTF-8');
                $meta_desc_encode = $programme->meta_description;
			  
				FormHelper::TextArea('meta_keywords',$meta_key_encode, 
									 'Meta Keywords', 
									 $programme_diff['meta_keywords']);
				FormHelper::TextArea('meta_description', $meta_desc_encode,
									 'Meta Description', 
									 $programme_diff['meta_description']);
				FormHelper::TextField('blog_url', $programme->blog_url,
									  'Programme Blog', 
									  $programme_diff['blog_url']);
				FormHelper::TextField('forum_id', 
									  $programme->forum_id, 
									  'Forum ID', 
									  $programme_diff['forum_id'], 
									  'number');
				FormHelper::TextField('minisite_url',$programme->minisite_url,
									  'Minisite URL', 
									  $programme_diff['minisite_url'],
                                      'ruler input_status', 
                                      0, 
                                      true);
			?>
    </fieldset>


        <a id="anchor-cast"></a>
    	<fieldset class="casts ui-widget-content">
			<legend class="ui-widget-header">Cast <?php if ($act == 'view' && in_array(true, $cast_highlight)) echo 'Update'; ?></legend>
			<?php FormHelper::GlobalNameInput($arr_cast, $cast_list, 0, '', $cast_highlight) ?>
	    </fieldset>

        <a id="anchor-crew"></a>
    	<fieldset class="casts ui-widget-content">
			<legend class="ui-widget-header">Crew <?php if ($act == 'view' && in_array(true, $crew_highlight) ) echo 'Update'; ?></legend>
			<?php FormHelper::GlobalNameInput($arr_crew, $crew_list, 0, '', $crew_highlight) ?>
	    </fieldset>

    <a id="anchor-video"></a>
    <fieldset class="ui-widget-content">
        <legend class="ui-widget-header">Video</legend>
<?php if($act != 'view'){ ?>        
        <div class="ui-helper-clearfix folder-manager-box">
            <a href="#video-programme-<?php echo $programme->id;?>" class="btn ui-state-default ui-corner-all folder-manager-btn" title="Manage Folders">Manage Folders</a>
		</div>
<?php } ?>
<?php
if (isset($video_folder_list['folders']) && (count($video_folder_list['folders']) > 0) ) {
	//FormHelper::RedCallers('forders', $video_folder_list);
	FormHelper::RedCallers2('forders', $video_folder_list);
}
?>
    </fieldset>

    <a id="anchor-image"></a>
    <fieldset class="ui-widget-content">
        <legend class="ui-widget-header">Image</legend>
<?php if($act != 'view'){ ?>        
        <div class="ui-helper-clearfix folder-manager-box">
            <a href="#image-programme-<?php echo $programme->id;?>" class="btn ui-state-default ui-corner-all folder-manager-btn" title="Manage Folders">Manage Folders</a>
        </div>
<?php } ?>
<?php
if (isset($image_folder_list['folders']) && (count($image_folder_list['folders']) > 0) ) {
	FormHelper::RedCallers('fordersrs', $image_folder_list); 
}
?>
    </fieldset>

    <fieldset class="ui-widget-content">
        <legend class="ui-widget-header">Record Status and Access Log</legend>
    	    <?php FormHelper::ProtectedField(AC::$op_status[$programme->status], 'Record Status',true) ?>
    	    <?php FormHelper::ProtectedField($programme->created_by, 'Created By') ?>
    	    <?php FormHelper::ProtectedField($programme->created_at, 'Created At') ?>
    	    <?php FormHelper::ProtectedField($programme->modified_by, 'Modified By') ?>
    	    <?php FormHelper::ProtectedField($programme->modified_at, 'Modified At') ?>
    </fieldset>

    <?php FormHelper::DisplayPublishLog($data['publishLog']); ?>
    <span class="buttons">
        <?php
            switch ($act) {
                case 'add':
                    ($step == 2) ? FormHelper::SubmitButton('update', 'Update') : FormHelper::SubmitButton('create', 'Create'); 
                    FormHelper::ResetButton('reset', 'Reset');
					($step == 2) ? FormHelper::Button('top', 'Top') : "";
                break;
                case 'edit':
                    FormHelper::SubmitButton('update', 'Update');
                    FormHelper::ResetButton('reset', 'Reset');
                	FormHelper::Button('back', 'Home');
					FormHelper::Button('top', 'Top');
                break;
				case 'view':
					/** modified by vanni for bug no:260 **/
					if($publish ==1){
                        CommonUtils::showUnpublishButton($data, $data['_g']);
					}else{
						if($programme->status == AC::STATUS_DELETED){
							FormHelper::SubmitButton('recover', 'Recover');
						}else{
							FormHelper::SubmitButton('edit', 'Edit');
							FormHelper::SubmitButton('rerun', 'Clone');
							# FormHelper::SubmitButton('clone', 'Clone');
                            CommonUtils::showDeleteButton($data['publishLog']);
                            CommonUtils::showPublishButton(!empty($programme->premium_flag), $data['_g']);
						}
					}
                	FormHelper::Button('back', 'Home');
					FormHelper::Button('top', 'Top');
                break;
            }
        ?>
        <!--
    	<?php FormHelper::Button('mam', 'MAM') ?> 
        -->
    </span>
    <?php FormHelper::EndForm() ?>

    </div>

</div>

<script>
    TVB.Pdes.oValidation = {
        form: document.forms['ane'],
        rules: <?php echo json_encode($validation_rules); ?>
    };
</script>
